{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "UCCSD ansatz.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OhBIxto-FE64",
        "colab_type": "text"
      },
      "source": [
        "### Install Qiskit"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uuZH1ldq-WA9",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "b3404a2f-8333-40cb-bdc7-377f10e32277"
      },
      "source": [
        "pip install qiskit"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Collecting qiskit\n",
            "  Downloading https://files.pythonhosted.org/packages/69/3d/e8f748f6e1b54714c691f6bb95c986c236576386d7a86c6b737dd84b281b/qiskit-0.11.0.tar.gz\n",
            "Collecting qiskit_terra==0.8.2 (from qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/71/52/ebfa1c41722ae5e04d2456677e6d492373d9b28eca5cdf86b8f2981b1e21/qiskit_terra-0.8.2-cp36-cp36m-manylinux1_x86_64.whl (1.5MB)\n",
            "\u001b[K     |████████████████████████████████| 1.5MB 5.1MB/s \n",
            "\u001b[?25hCollecting qiskit-aer==0.2.3 (from qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/1c/f6/10bb8a7b8939623a5ffedc844f7bba535b00a014292a58a82893e966bbde/qiskit_aer-0.2.3-cp36-cp36m-manylinux1_x86_64.whl (21.3MB)\n",
            "\u001b[K     |████████████████████████████████| 21.3MB 1.0MB/s \n",
            "\u001b[?25hCollecting qiskit-ibmq-provider==0.3.0 (from qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/90/b9/fd1997a20bc26e689b2987e196779ae8ce8c8052fc2a49baa50edfda8d99/qiskit-ibmq-provider-0.3.0.tar.gz (56kB)\n",
            "\u001b[K     |████████████████████████████████| 61kB 22.3MB/s \n",
            "\u001b[?25hCollecting qiskit-ignis==0.1.1 (from qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/6e/4e/77230b3a51a864fd54c2ef7b6a0d417063cf4b18943ce8fcd45e15f74f3e/qiskit_ignis-0.1.1-py3-none-any.whl (78kB)\n",
            "\u001b[K     |████████████████████████████████| 81kB 27.2MB/s \n",
            "\u001b[?25hCollecting qiskit-aqua==0.5.2 (from qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/3d/2c/18f987e2b673b0c47f6293f6d2c51e1f6db176744c81321f6cf28614d458/qiskit_aqua-0.5.2-py3-none-any.whl (401kB)\n",
            "\u001b[K     |████████████████████████████████| 409kB 44.9MB/s \n",
            "\u001b[?25hCollecting qiskit-chemistry==0.5.0 (from qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/41/35/6b10aa3ea2fbe1b64cb0c3b2eaecb23cff044b574b151e8adc9ab9fbfe9a/qiskit_chemistry-0.5.0-py3-none-any.whl (516kB)\n",
            "\u001b[K     |████████████████████████████████| 522kB 40.5MB/s \n",
            "\u001b[?25hRequirement already satisfied: jsonschema<2.7,>=2.6 in /usr/local/lib/python3.6/dist-packages (from qiskit_terra==0.8.2->qiskit) (2.6.0)\n",
            "Collecting pylatexenc>=1.4 (from qiskit_terra==0.8.2->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/2d/44/93573fef5cb46842ce9a87548008bea92c8f7523c7c2152cfdffee269ed5/pylatexenc-1.5.tar.gz (47kB)\n",
            "\u001b[K     |████████████████████████████████| 51kB 19.1MB/s \n",
            "\u001b[?25hCollecting sympy>=1.3 (from qiskit_terra==0.8.2->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/21/21/f4105795ca7f35c541d82c5b06be684dd2f5cb4f508fb487cd7aea4de776/sympy-1.4-py2.py3-none-any.whl (5.3MB)\n",
            "\u001b[K     |████████████████████████████████| 5.3MB 32.7MB/s \n",
            "\u001b[?25hCollecting marshmallow<3,>=2.17.0 (from qiskit_terra==0.8.2->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/77/0b/ee5a4d0b7bc88bb3b59a25fb40e1811810c039f7faa1e87dcdcbcb1fdc33/marshmallow-2.19.5-py2.py3-none-any.whl (50kB)\n",
            "\u001b[K     |████████████████████████████████| 51kB 19.1MB/s \n",
            "\u001b[?25hCollecting marshmallow-polyfield<4,>=3.2 (from qiskit_terra==0.8.2->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/fa/ba/6406b8cce3e42b2838d234310c3605627083bbb8f71dcc312c616480fe92/marshmallow_polyfield-3.2-py2.py3-none-any.whl\n",
            "Collecting ply>=3.10 (from qiskit_terra==0.8.2->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/a3/58/35da89ee790598a0700ea49b2a66594140f44dec458c07e8e3d4979137fc/ply-3.11-py2.py3-none-any.whl (49kB)\n",
            "\u001b[K     |████████████████████████████████| 51kB 21.2MB/s \n",
            "\u001b[?25hRequirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.6/dist-packages (from qiskit_terra==0.8.2->qiskit) (1.3.0)\n",
            "Requirement already satisfied: psutil>=5 in /usr/local/lib/python3.6/dist-packages (from qiskit_terra==0.8.2->qiskit) (5.4.8)\n",
            "Requirement already satisfied: numpy>=1.13 in /usr/local/lib/python3.6/dist-packages (from qiskit_terra==0.8.2->qiskit) (1.16.4)\n",
            "Requirement already satisfied: networkx>=2.2 in /usr/local/lib/python3.6/dist-packages (from qiskit_terra==0.8.2->qiskit) (2.3)\n",
            "Requirement already satisfied: pillow>=4.2.1 in /usr/local/lib/python3.6/dist-packages (from qiskit_terra==0.8.2->qiskit) (4.3.0)\n",
            "Collecting nest-asyncio>=1.0.0 (from qiskit-ibmq-provider==0.3.0->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/62/18/4c6a895c925e8822e72535d774861e9ca07089c4b938ed20002b1aaab66a/nest_asyncio-1.0.0-py3-none-any.whl\n",
            "Requirement already satisfied: requests>=2.19 in /usr/local/lib/python3.6/dist-packages (from qiskit-ibmq-provider==0.3.0->qiskit) (2.21.0)\n",
            "Collecting requests-ntlm>=1.1.0 (from qiskit-ibmq-provider==0.3.0->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/03/4b/8b9a1afde8072c4d5710d9fa91433d504325821b038e00237dc8d6d833dc/requests_ntlm-1.1.0-py2.py3-none-any.whl\n",
            "Collecting websockets<8,>=7 (from qiskit-ibmq-provider==0.3.0->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/43/71/8bfa882b9c502c36e5c9ef6732969533670d2b039cbf95a82ced8f762b80/websockets-7.0-cp36-cp36m-manylinux1_x86_64.whl (63kB)\n",
            "\u001b[K     |████████████████████████████████| 71kB 24.3MB/s \n",
            "\u001b[?25hCollecting docplex (from qiskit-aqua==0.5.2->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/06/bc/b17191a0f8595763aba75c4ae5cc0f44be594c8d75aed737c42cf167c73f/docplex-2.10.150.tar.gz (528kB)\n",
            "\u001b[K     |████████████████████████████████| 532kB 46.4MB/s \n",
            "\u001b[?25hRequirement already satisfied: setuptools>=40.1.0 in /usr/local/lib/python3.6/dist-packages (from qiskit-aqua==0.5.2->qiskit) (41.0.1)\n",
            "Collecting dlx (from qiskit-aqua==0.5.2->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/54/c0/b8fb5bb727e983b6f5251433ef941b48f38c65bb0bd6ec509e9185bcd406/dlx-1.0.4.tar.gz\n",
            "Collecting quandl (from qiskit-aqua==0.5.2->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/12/64/6314547cb01fa75697ddba6d6d43a9f1d023c1730ffc6abf3db7a0c89222/Quandl-3.4.8-py2.py3-none-any.whl\n",
            "Requirement already satisfied: fastdtw in /usr/local/lib/python3.6/dist-packages (from qiskit-aqua==0.5.2->qiskit) (0.3.2)\n",
            "Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.6/dist-packages (from qiskit-aqua==0.5.2->qiskit) (0.21.2)\n",
            "Requirement already satisfied: cvxopt in /usr/local/lib/python3.6/dist-packages (from qiskit-aqua==0.5.2->qiskit) (1.2.3)\n",
            "Collecting pyscf; sys_platform != \"win32\" (from qiskit-chemistry==0.5.0->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/db/4b/2a82e6f6dc24fceaf2cb1e2537796b0e9b7f3187d8008ef1f48e2cacb728/pyscf-1.6.2-cp36-cp36m-manylinux1_x86_64.whl (21.5MB)\n",
            "\u001b[K     |████████████████████████████████| 21.5MB 22.6MB/s \n",
            "\u001b[?25hRequirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (from qiskit-chemistry==0.5.0->qiskit) (2.8.0)\n",
            "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.6/dist-packages (from sympy>=1.3->qiskit_terra==0.8.2->qiskit) (1.1.0)\n",
            "Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.6/dist-packages (from networkx>=2.2->qiskit_terra==0.8.2->qiskit) (4.4.0)\n",
            "Requirement already satisfied: olefile in /usr/local/lib/python3.6/dist-packages (from pillow>=4.2.1->qiskit_terra==0.8.2->qiskit) (0.46)\n",
            "Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.3.0->qiskit) (1.24.3)\n",
            "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.3.0->qiskit) (3.0.4)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.3.0->qiskit) (2019.6.16)\n",
            "Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.3.0->qiskit) (2.8)\n",
            "Collecting ntlm-auth>=1.0.2 (from requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.3.0->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/d5/3d/1c54e92f62bbc747a638da94adb439f99dc2d2f3041fe41a06b0da4f2808/ntlm_auth-1.3.0-py2.py3-none-any.whl\n",
            "Collecting cryptography>=1.3 (from requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.3.0->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/97/18/c6557f63a6abde34707196fb2cad1c6dc0dbff25a200d5044922496668a4/cryptography-2.7-cp34-abi3-manylinux1_x86_64.whl (2.3MB)\n",
            "\u001b[K     |████████████████████████████████| 2.3MB 32.2MB/s \n",
            "\u001b[?25hRequirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from docplex->qiskit-aqua==0.5.2->qiskit) (1.12.0)\n",
            "Collecting docloud>=1.0.369 (from docplex->qiskit-aqua==0.5.2->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/89/1c/fcb7ea86ae5cb7137a22f00bcaa785de2d102bd4a2b16383ec4a877a835b/docloud-1.0.375.tar.gz\n",
            "Collecting more-itertools<=5.0.0 (from quandl->qiskit-aqua==0.5.2->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/a4/a6/42f17d065bda1fac255db13afc94c93dbfb64393eae37c749b4cb0752fc7/more_itertools-5.0.0-py3-none-any.whl (52kB)\n",
            "\u001b[K     |████████████████████████████████| 61kB 22.9MB/s \n",
            "\u001b[?25hCollecting ndg-httpsclient (from quandl->qiskit-aqua==0.5.2->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/fb/67/c2f508c00ed2a6911541494504b7cac16fe0b0473912568df65fd1801132/ndg_httpsclient-0.5.1-py3-none-any.whl\n",
            "Requirement already satisfied: pandas>=0.14 in /usr/local/lib/python3.6/dist-packages (from quandl->qiskit-aqua==0.5.2->qiskit) (0.24.2)\n",
            "Requirement already satisfied: pyasn1 in /usr/local/lib/python3.6/dist-packages (from quandl->qiskit-aqua==0.5.2->qiskit) (0.4.5)\n",
            "Collecting pyOpenSSL (from quandl->qiskit-aqua==0.5.2->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/01/c8/ceb170d81bd3941cbeb9940fc6cc2ef2ca4288d0ca8929ea4db5905d904d/pyOpenSSL-19.0.0-py2.py3-none-any.whl (53kB)\n",
            "\u001b[K     |████████████████████████████████| 61kB 23.3MB/s \n",
            "\u001b[?25hRequirement already satisfied: python-dateutil in /usr/local/lib/python3.6/dist-packages (from quandl->qiskit-aqua==0.5.2->qiskit) (2.5.3)\n",
            "Collecting inflection>=0.3.1 (from quandl->qiskit-aqua==0.5.2->qiskit)\n",
            "  Downloading https://files.pythonhosted.org/packages/d5/35/a6eb45b4e2356fe688b21570864d4aa0d0a880ce387defe9c589112077f8/inflection-0.3.1.tar.gz\n",
            "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.6/dist-packages (from scikit-learn>=0.20.0->qiskit-aqua==0.5.2->qiskit) (0.13.2)\n",
            "Collecting asn1crypto>=0.21.0 (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.3.0->qiskit)\n",
            "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)\n",
            "\u001b[K     |████████████████████████████████| 102kB 29.0MB/s \n",
            "\u001b[?25hRequirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/local/lib/python3.6/dist-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.3.0->qiskit) (1.12.3)\n",
            "Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/dist-packages (from pandas>=0.14->quandl->qiskit-aqua==0.5.2->qiskit) (2018.9)\n",
            "Requirement already satisfied: pycparser in /usr/local/lib/python3.6/dist-packages (from cffi!=1.11.3,>=1.8->cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.3.0->qiskit) (2.19)\n",
            "Building wheels for collected packages: qiskit, qiskit-ibmq-provider, pylatexenc, docplex, dlx, docloud, inflection\n",
            "  Building wheel for qiskit (setup.py) ... \u001b[?25lerror\n",
            "\u001b[31m  ERROR: Failed building wheel for qiskit\u001b[0m\n",
            "\u001b[?25h  Running setup.py clean for qiskit\n",
            "  Building wheel for qiskit-ibmq-provider (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Stored in directory: /root/.cache/pip/wheels/0c/56/e7/b07b4d2f19fd4c5fff7fe334c72eb313fecf04fa693a7c558e\n",
            "  Building wheel for pylatexenc (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Stored in directory: /root/.cache/pip/wheels/da/d1/f1/fa2d005ecda8836039af952de8f4bf1defd42fe385027b6f52\n",
            "  Building wheel for docplex (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Stored in directory: /root/.cache/pip/wheels/6b/9d/3a/25dc38df1a476f24a36f1f3c285b696a28273d00124b571c08\n",
            "  Building wheel for dlx (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Stored in directory: /root/.cache/pip/wheels/bb/ba/15/fdd0deb104df3254912998150ba9245668db06b00af5912d1a\n",
            "  Building wheel for docloud (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Stored in directory: /root/.cache/pip/wheels/4e/24/19/9b0e57545d7543ecec35c5faff78c058bf0c2506369c8b1d31\n",
            "  Building wheel for inflection (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Stored in directory: /root/.cache/pip/wheels/9f/5a/d3/6fc3bf6516d2a3eb7e18f9f28b472110b59325f3f258fe9211\n",
            "Successfully built qiskit-ibmq-provider pylatexenc docplex dlx docloud inflection\n",
            "Failed to build qiskit\n",
            "\u001b[31mERROR: datascience 0.10.6 has requirement folium==0.2.1, but you'll have folium 0.8.3 which is incompatible.\u001b[0m\n",
            "Installing collected packages: pylatexenc, sympy, marshmallow, marshmallow-polyfield, ply, qiskit-terra, qiskit-aer, nest-asyncio, ntlm-auth, asn1crypto, cryptography, requests-ntlm, websockets, qiskit-ibmq-provider, qiskit-ignis, docloud, docplex, dlx, more-itertools, pyOpenSSL, ndg-httpsclient, inflection, quandl, qiskit-aqua, pyscf, qiskit-chemistry, qiskit\n",
            "  Found existing installation: sympy 1.1.1\n",
            "    Uninstalling sympy-1.1.1:\n",
            "      Successfully uninstalled sympy-1.1.1\n",
            "  Found existing installation: more-itertools 7.1.0\n",
            "    Uninstalling more-itertools-7.1.0:\n",
            "      Successfully uninstalled more-itertools-7.1.0\n",
            "  Running setup.py install for qiskit ... \u001b[?25l\u001b[?25hdone\n",
            "Successfully installed asn1crypto-0.24.0 cryptography-2.7 dlx-1.0.4 docloud-1.0.375 docplex-2.10.150 inflection-0.3.1 marshmallow-2.19.5 marshmallow-polyfield-3.2 more-itertools-5.0.0 ndg-httpsclient-0.5.1 nest-asyncio-1.0.0 ntlm-auth-1.3.0 ply-3.11 pyOpenSSL-19.0.0 pylatexenc-1.5 pyscf-1.6.2 qiskit-0.11.0 qiskit-aer-0.2.3 qiskit-aqua-0.5.2 qiskit-chemistry-0.5.0 qiskit-ibmq-provider-0.3.0 qiskit-ignis-0.1.1 qiskit-terra-0.8.2 quandl-3.4.8 requests-ntlm-1.1.0 sympy-1.4 websockets-7.0\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wDxLtCp9-NV-",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# import common packages\n",
        "import numpy as np\n",
        "\n",
        "from qiskit import Aer\n",
        "\n",
        "# lib from Qiskit Aqua\n",
        "from qiskit.aqua import Operator, QuantumInstance\n",
        "from qiskit.aqua.algorithms import VQE, ExactEigensolver\n",
        "from qiskit.aqua.components.optimizers import COBYLA\n",
        "\n",
        "# lib from Qiskit Aqua Chemistry\n",
        "from qiskit.chemistry import FermionicOperator\n",
        "from qiskit.chemistry.drivers import PySCFDriver, UnitsType\n",
        "from qiskit.chemistry.aqua_extensions.components.variational_forms import UCCSD\n",
        "from qiskit.chemistry.aqua_extensions.components.initial_states import HartreeFock"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BygVALbGFKKN",
        "colab_type": "text"
      },
      "source": [
        "### Set up the molecular structure"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dD0KY-mo-TgT",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.72', unit=UnitsType.ANGSTROM, basis='sto3g')\n",
        "molecule = driver.run()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8sUtJGzS_CBt",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        },
        "outputId": "c5ee0adf-5484-4a7a-ea1a-dbeedfe8b21b"
      },
      "source": [
        "h1 = molecule.one_body_integrals\n",
        "h2 = molecule.two_body_integrals\n",
        "nuclear_repulsion_energy = molecule.nuclear_repulsion_energy\n",
        "\n",
        "num_particles = molecule.num_alpha + molecule.num_beta\n",
        "num_spin_orbitals = molecule.num_orbitals * 2\n",
        "print(\"HF energy: {}\".format(molecule.hf_energy))\n",
        "print(\"# of electrons: {}\".format(num_particles))\n",
        "print(\"# of spin orbitals: {}\".format(num_spin_orbitals))"
      ],
      "execution_count": 92,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "HF energy: -1.1174450773714701\n",
            "# of electrons: 2\n",
            "# of spin orbitals: 4\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "19oyuNJGFO7H",
        "colab_type": "text"
      },
      "source": [
        "### Choose your mapping"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1eodmBhS_9GR",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "map_type = 'jordan_wigner'"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yu9YhTrJFWaj",
        "colab_type": "text"
      },
      "source": [
        "### Generate the Pauli strings"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "L8Sdeer3_HvN",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 306
        },
        "outputId": "8d05f6df-db13-4960-feb3-04342912c75b"
      },
      "source": [
        "ferOp = FermionicOperator(h1=h1, h2=h2)\n",
        "qubitOp = ferOp.mapping(map_type=map_type, threshold=0.00000001)\n",
        "\n",
        "\n",
        "print(qubitOp.print_operators())\n",
        "print(qubitOp)"
      ],
      "execution_count": 24,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "IIII\t(-0.8362123048044218+0j)\n",
            "IIIZ\t(0.08705553358137133+0j)\n",
            "IIZI\t(-0.024253213726949913+0j)\n",
            "IZII\t(0.08705553358137129+0j)\n",
            "ZIII\t(-0.02425321372694993+0j)\n",
            "IIZZ\t(0.07854309838088275+0j)\n",
            "IZIZ\t(0.13546887571547914+0j)\n",
            "XXYY\t(0.05897532134962703+0j)\n",
            "YYYY\t(0.05897532134962703+0j)\n",
            "XXXX\t(0.05897532134962703+0j)\n",
            "YYXX\t(0.05897532134962703+0j)\n",
            "ZIIZ\t(0.1375184197305098+0j)\n",
            "IZZI\t(0.1375184197305098+0j)\n",
            "ZIZI\t(0.14301575315731474+0j)\n",
            "ZZII\t(0.07854309838088275+0j)\n",
            "\n",
            "Representation: paulis, qubits: 4, size: 15\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-MvTKVKMFaXd",
        "colab_type": "text"
      },
      "source": [
        "### Set up the Hartree Fock states"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QrRK3oby_Xxr",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "qubit_reduction = False\n",
        "HF_state = HartreeFock(qubitOp.num_qubits, num_spin_orbitals, num_particles, map_type, \n",
        "                       qubit_reduction)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vUZ3Cj2aFdka",
        "colab_type": "text"
      },
      "source": [
        "### Set up the UCCSD ansatzs"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "1Mtwpkd6_dHW",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "96789c27-96a5-4806-d391-09b3437c692b"
      },
      "source": [
        "uccsd_ansatz = UCCSD(qubitOp.num_qubits, depth=1, \n",
        "                   num_orbitals=num_spin_orbitals, num_particles=num_particles,\n",
        "                   initial_state=HF_state, qubit_mapping=map_type, \n",
        "                   two_qubit_reduction=qubit_reduction)\n",
        "list = np.random.rand(3)\n",
        "print(list)\n",
        "uccsd_ansatz_circuit = uccsd_ansatz.construct_circuit(list)"
      ],
      "execution_count": 58,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[0.8492349  0.28429897 0.57207906]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IORgPtD8G3zo",
        "colab_type": "text"
      },
      "source": [
        "### Visualize the UCCSD ansatz circuit"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vipW9YQ4BrOZ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "64971aa3-8721-4c3e-e225-bf01c2d7d772"
      },
      "source": [
        "print(uccsd_ansatz_circuit)"
      ],
      "execution_count": 59,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "        ┌─────────────────────┐┌──────────┐                         »\n",
            "q_0: |0>┤ U3(3.1416,0,3.1416) ├┤ U2(0,pi) ├──■───────────────────■──»\n",
            "        ├─────────────────────┤└──────────┘┌─┴─┐┌─────────────┐┌─┴─┐»\n",
            "q_1: |0>┤ U3(pi/2,-pi/2,pi/2) ├────────────┤ X ├┤ U1(0.84923) ├┤ X ├»\n",
            "        ├─────────────────────┤┌──────────┐└───┘└─────────────┘└───┘»\n",
            "q_2: |0>┤ U3(3.1416,0,3.1416) ├┤ U2(0,pi) ├──■───────────────────■──»\n",
            "        ├─────────────────────┤└──────────┘┌─┴─┐ ┌────────────┐┌─┴─┐»\n",
            "q_3: |0>┤ U3(pi/2,-pi/2,pi/2) ├────────────┤ X ├─┤ U1(0.2843) ├┤ X ├»\n",
            "        └─────────────────────┘            └───┘ └────────────┘└───┘»\n",
            "«           ┌──────────┐      ┌─────────────────────┐                          »\n",
            "«q_0: ──────┤ U2(0,pi) ├──────┤ U3(pi/2,-pi/2,pi/2) ├──■────────────────────■──»\n",
            "«     ┌─────┴──────────┴─────┐└─────┬──────────┬────┘┌─┴─┐┌──────────────┐┌─┴─┐»\n",
            "«q_1: ┤ U3(-pi/2,-pi/2,pi/2) ├──────┤ U2(0,pi) ├─────┤ X ├┤ U1(-0.84923) ├┤ X ├»\n",
            "«     └─────┬──────────┬─────┘┌─────┴──────────┴────┐└───┘└──────────────┘└───┘»\n",
            "«q_2: ──────┤ U2(0,pi) ├──────┤ U3(pi/2,-pi/2,pi/2) ├──■────────────────────■──»\n",
            "«     ┌─────┴──────────┴─────┐└─────┬──────────┬────┘┌─┴─┐┌─────────────┐ ┌─┴─┐»\n",
            "«q_3: ┤ U3(-pi/2,-pi/2,pi/2) ├──────┤ U2(0,pi) ├─────┤ X ├┤ U1(-0.2843) ├─┤ X ├»\n",
            "«     └──────────────────────┘      └──────────┘     └───┘└─────────────┘ └───┘»\n",
            "«     ┌──────────────────────┐      ┌──────────┐                    »\n",
            "«q_0: ┤ U3(-pi/2,-pi/2,pi/2) ├──────┤ U2(0,pi) ├───────■────────────»\n",
            "«     └─────┬──────────┬─────┘      ├──────────┤     ┌─┴─┐          »\n",
            "«q_1: ──────┤ U2(0,pi) ├────────────┤ U2(0,pi) ├─────┤ X ├──■───────»\n",
            "«     ┌─────┴──────────┴─────┐      ├──────────┤     └───┘┌─┴─┐     »\n",
            "«q_2: ┤ U3(-pi/2,-pi/2,pi/2) ├──────┤ U2(0,pi) ├──────────┤ X ├──■──»\n",
            "«     └─────┬──────────┬─────┘┌─────┴──────────┴────┐     └───┘┌─┴─┐»\n",
            "«q_3: ──────┤ U2(0,pi) ├──────┤ U3(pi/2,-pi/2,pi/2) ├──────────┤ X ├»\n",
            "«           └──────────┘      └─────────────────────┘          └───┘»\n",
            "«                                                             ┌──────────┐»\n",
            "«q_0: ─────────────────────────────────────────────────■──────┤ U2(0,pi) ├»\n",
            "«                                                    ┌─┴─┐    ├──────────┤»\n",
            "«q_1: ───────────────────────────────■───────────────┤ X ├────┤ U2(0,pi) ├»\n",
            "«                                  ┌─┴─┐          ┌──┴───┴───┐├──────────┤»\n",
            "«q_2: ─────────────────■───────────┤ X ├──────────┤ U2(0,pi) ├┤ U2(0,pi) ├»\n",
            "«     ┌─────────────┐┌─┴─┐┌────────┴───┴─────────┐├──────────┤└──────────┘»\n",
            "«q_3: ┤ U1(0.14302) ├┤ X ├┤ U3(-pi/2,-pi/2,pi/2) ├┤ U2(0,pi) ├────────────»\n",
            "«     └─────────────┘└───┘└──────────────────────┘└──────────┘            »\n",
            "«           ┌──────────┐                                                    »\n",
            "«q_0: ──────┤ U2(0,pi) ├───────■────────────────────────────────────────────»\n",
            "«     ┌─────┴──────────┴────┐┌─┴─┐                                          »\n",
            "«q_1: ┤ U3(pi/2,-pi/2,pi/2) ├┤ X ├──■────────────────────────────────■──────»\n",
            "«     └─────────────────────┘└───┘┌─┴─┐                            ┌─┴─┐    »\n",
            "«q_2: ────────────────────────────┤ X ├──■───────────────────■─────┤ X ├────»\n",
            "«                                 └───┘┌─┴─┐┌─────────────┐┌─┴─┐┌──┴───┴───┐»\n",
            "«q_3: ─────────────────────────────────┤ X ├┤ U1(0.14302) ├┤ X ├┤ U2(0,pi) ├»\n",
            "«                                      └───┘└─────────────┘└───┘└──────────┘»\n",
            "«                                  ┌──────────┐            ┌──────────┐     »\n",
            "«q_0: ───────────■─────────────────┤ U2(0,pi) ├────────────┤ U2(0,pi) ├─────»\n",
            "«              ┌─┴─┐         ┌─────┴──────────┴─────┐┌─────┴──────────┴────┐»\n",
            "«q_1: ─────────┤ X ├─────────┤ U3(-pi/2,-pi/2,pi/2) ├┤ U3(pi/2,-pi/2,pi/2) ├»\n",
            "«           ┌──┴───┴───┐     ├─────────────────────┬┘└─────────────────────┘»\n",
            "«q_2: ──────┤ U2(0,pi) ├─────┤ U3(pi/2,-pi/2,pi/2) ├────────────────────────»\n",
            "«     ┌─────┴──────────┴────┐└─────────────────────┘                        »\n",
            "«q_3: ┤ U3(pi/2,-pi/2,pi/2) ├───────────────────────────────────────────────»\n",
            "«     └─────────────────────┘                                               »\n",
            "«                                                                »\n",
            "«q_0: ──■────────────────────────────────────────────────────────»\n",
            "«     ┌─┴─┐                                                      »\n",
            "«q_1: ┤ X ├──■──────────────────────────────────────■────────────»\n",
            "«     └───┘┌─┴─┐                                  ┌─┴─┐          »\n",
            "«q_2: ─────┤ X ├──■───────────────────■───────────┤ X ├──────────»\n",
            "«          └───┘┌─┴─┐┌─────────────┐┌─┴─┐┌────────┴───┴─────────┐»\n",
            "«q_3: ──────────┤ X ├┤ U1(0.14302) ├┤ X ├┤ U3(-pi/2,-pi/2,pi/2) ├»\n",
            "«               └───┘└─────────────┘└───┘└──────────────────────┘»\n",
            "«                                   ┌──────────┐      ┌──────────┐          »\n",
            "«q_0: ───────────■──────────────────┤ U2(0,pi) ├──────┤ U2(0,pi) ├──■───────»\n",
            "«              ┌─┴─┐          ┌─────┴──────────┴─────┐├──────────┤┌─┴─┐     »\n",
            "«q_1: ─────────┤ X ├──────────┤ U3(-pi/2,-pi/2,pi/2) ├┤ U2(0,pi) ├┤ X ├──■──»\n",
            "«     ┌────────┴───┴─────────┐├─────────────────────┬┘└──────────┘└───┘┌─┴─┐»\n",
            "«q_2: ┤ U3(-pi/2,-pi/2,pi/2) ├┤ U3(pi/2,-pi/2,pi/2) ├──────────────────┤ X ├»\n",
            "«     └─────┬──────────┬─────┘└─────────────────────┘                  └───┘»\n",
            "«q_3: ──────┤ U2(0,pi) ├────────────────────────────────────────────────────»\n",
            "«           └──────────┘                                                    »\n",
            "«                                                                   »\n",
            "«q_0: ─────────────────────────────────────────────────■────────────»\n",
            "«                                                    ┌─┴─┐          »\n",
            "«q_1: ───────────────────────────────■───────────────┤ X ├──────────»\n",
            "«                                  ┌─┴─┐    ┌────────┴───┴─────────┐»\n",
            "«q_2: ──■────────────────────■─────┤ X ├────┤ U3(-pi/2,-pi/2,pi/2) ├»\n",
            "«     ┌─┴─┐┌──────────────┐┌─┴─┐┌──┴───┴───┐├─────────────────────┬┘»\n",
            "«q_3: ┤ X ├┤ U1(-0.14302) ├┤ X ├┤ U2(0,pi) ├┤ U3(pi/2,-pi/2,pi/2) ├─»\n",
            "«     └───┘└──────────────┘└───┘└──────────┘└─────────────────────┘ »\n",
            "«     ┌──────────┐┌─────────────────────┐                                   »\n",
            "«q_0: ┤ U2(0,pi) ├┤ U3(pi/2,-pi/2,pi/2) ├──■────────────────────────────────»\n",
            "«     ├──────────┤├─────────────────────┤┌─┴─┐                              »\n",
            "«q_1: ┤ U2(0,pi) ├┤ U3(pi/2,-pi/2,pi/2) ├┤ X ├──■───────────────────────────»\n",
            "«     ├──────────┤└─────────────────────┘└───┘┌─┴─┐                         »\n",
            "«q_2: ┤ U2(0,pi) ├────────────────────────────┤ X ├──■───────────────────■──»\n",
            "«     └──────────┘                            └───┘┌─┴─┐┌─────────────┐┌─┴─┐»\n",
            "«q_3: ─────────────────────────────────────────────┤ X ├┤ U1(0.14302) ├┤ X ├»\n",
            "«                                                  └───┘└─────────────┘└───┘»\n",
            "«                                         ┌──────────────────────┐»\n",
            "«q_0: ─────────────────────────────■──────┤ U3(-pi/2,-pi/2,pi/2) ├»\n",
            "«                                ┌─┴─┐    ├──────────────────────┤»\n",
            "«q_1: ───────────■───────────────┤ X ├────┤ U3(-pi/2,-pi/2,pi/2) ├»\n",
            "«              ┌─┴─┐          ┌──┴───┴───┐└─────┬──────────┬─────┘»\n",
            "«q_2: ─────────┤ X ├──────────┤ U2(0,pi) ├──────┤ U2(0,pi) ├──────»\n",
            "«     ┌────────┴───┴─────────┐├──────────┤      └──────────┘      »\n",
            "«q_3: ┤ U3(-pi/2,-pi/2,pi/2) ├┤ U2(0,pi) ├────────────────────────»\n",
            "«     └──────────────────────┘└──────────┘                        »\n",
            "«     ┌─────────────────────┐                                                »\n",
            "«q_0: ┤ U3(pi/2,-pi/2,pi/2) ├──■─────────────────────────────────────────────»\n",
            "«     └─────┬──────────┬────┘┌─┴─┐                                           »\n",
            "«q_1: ──────┤ U2(0,pi) ├─────┤ X ├──■─────────────────────────────────■──────»\n",
            "«           └──────────┘     └───┘┌─┴─┐                             ┌─┴─┐    »\n",
            "«q_2: ────────────────────────────┤ X ├──■────────────────────■─────┤ X ├────»\n",
            "«                                 └───┘┌─┴─┐┌──────────────┐┌─┴─┐┌──┴───┴───┐»\n",
            "«q_3: ─────────────────────────────────┤ X ├┤ U1(-0.14302) ├┤ X ├┤ U2(0,pi) ├»\n",
            "«                                      └───┘└──────────────┘└───┘└──────────┘»\n",
            "«                            ┌──────────────────────┐┌─────────────────────┐»\n",
            "«q_0: ───────────■───────────┤ U3(-pi/2,-pi/2,pi/2) ├┤ U3(pi/2,-pi/2,pi/2) ├»\n",
            "«              ┌─┴─┐         └─────┬──────────┬─────┘└─────┬──────────┬────┘»\n",
            "«q_1: ─────────┤ X ├───────────────┤ U2(0,pi) ├────────────┤ U2(0,pi) ├─────»\n",
            "«           ┌──┴───┴───┐     ┌─────┴──────────┴────┐       └──────────┘     »\n",
            "«q_2: ──────┤ U2(0,pi) ├─────┤ U3(pi/2,-pi/2,pi/2) ├────────────────────────»\n",
            "«     ┌─────┴──────────┴────┐└─────────────────────┘                        »\n",
            "«q_3: ┤ U3(pi/2,-pi/2,pi/2) ├───────────────────────────────────────────────»\n",
            "«     └─────────────────────┘                                               »\n",
            "«                                                                 »\n",
            "«q_0: ──■─────────────────────────────────────────────────────────»\n",
            "«     ┌─┴─┐                                                       »\n",
            "«q_1: ┤ X ├──■───────────────────────────────────────■────────────»\n",
            "«     └───┘┌─┴─┐                                   ┌─┴─┐          »\n",
            "«q_2: ─────┤ X ├──■────────────────────■───────────┤ X ├──────────»\n",
            "«          └───┘┌─┴─┐┌──────────────┐┌─┴─┐┌────────┴───┴─────────┐»\n",
            "«q_3: ──────────┤ X ├┤ U1(-0.14302) ├┤ X ├┤ U3(-pi/2,-pi/2,pi/2) ├»\n",
            "«               └───┘└──────────────┘└───┘└──────────────────────┘»\n",
            "«                             ┌──────────────────────┐┌─────────────────────┐»\n",
            "«q_0: ───────────■────────────┤ U3(-pi/2,-pi/2,pi/2) ├┤ U3(pi/2,-pi/2,pi/2) ├»\n",
            "«              ┌─┴─┐          └─────┬──────────┬─────┘├─────────────────────┤»\n",
            "«q_1: ─────────┤ X ├────────────────┤ U2(0,pi) ├──────┤ U3(pi/2,-pi/2,pi/2) ├»\n",
            "«     ┌────────┴───┴─────────┐┌─────┴──────────┴────┐ └─────────────────────┘»\n",
            "«q_2: ┤ U3(-pi/2,-pi/2,pi/2) ├┤ U3(pi/2,-pi/2,pi/2) ├────────────────────────»\n",
            "«     └─────┬──────────┬─────┘└─────────────────────┘                        »\n",
            "«q_3: ──────┤ U2(0,pi) ├─────────────────────────────────────────────────────»\n",
            "«           └──────────┘                                                     »\n",
            "«                                                                             »\n",
            "«q_0: ──■────────────────────────────────────────────────────────■────────────»\n",
            "«     ┌─┴─┐                                                    ┌─┴─┐          »\n",
            "«q_1: ┤ X ├──■─────────────────────────────────■───────────────┤ X ├──────────»\n",
            "«     └───┘┌─┴─┐                             ┌─┴─┐    ┌────────┴───┴─────────┐»\n",
            "«q_2: ─────┤ X ├──■────────────────────■─────┤ X ├────┤ U3(-pi/2,-pi/2,pi/2) ├»\n",
            "«          └───┘┌─┴─┐┌──────────────┐┌─┴─┐┌──┴───┴───┐└──────────────────────┘»\n",
            "«q_3: ──────────┤ X ├┤ U1(-0.14302) ├┤ X ├┤ U2(0,pi) ├────────────────────────»\n",
            "«               └───┘└──────────────┘└───┘└──────────┘                        »\n",
            "«     ┌──────────────────────┐\n",
            "«q_0: ┤ U3(-pi/2,-pi/2,pi/2) ├\n",
            "«     ├──────────────────────┤\n",
            "«q_1: ┤ U3(-pi/2,-pi/2,pi/2) ├\n",
            "«     └──────────────────────┘\n",
            "«q_2: ────────────────────────\n",
            "«                             \n",
            "«q_3: ────────────────────────\n",
            "«                             \n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9_IReyc1HL_R",
        "colab_type": "text"
      },
      "source": [
        "### Convert the circuit to OpenQASM code"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fP9MfJMSHD1M",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "7e1215eb-b4e0-4c1b-a006-41bf49543fcc"
      },
      "source": [
        "print(uccsd_ansatz_circuit.qasm())"
      ],
      "execution_count": 60,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "OPENQASM 2.0;\n",
            "include \"qelib1.inc\";\n",
            "qreg q[4];\n",
            "u3(3.14159265358979,0.0,3.14159265358979) q[0];\n",
            "u3(3.14159265358979,0.0,3.14159265358979) q[2];\n",
            "u2(0.0,pi) q[0];\n",
            "u3(pi/2,-pi/2,pi/2) q[1];\n",
            "cx q[0],q[1];\n",
            "u1(0.849234900739678) q[1];\n",
            "cx q[0],q[1];\n",
            "u2(0.0,pi) q[0];\n",
            "u3(-pi/2,-pi/2,pi/2) q[1];\n",
            "u3(pi/2,-pi/2,pi/2) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "cx q[0],q[1];\n",
            "u1(-0.849234900739678) q[1];\n",
            "cx q[0],q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u3(pi/2,-pi/2,pi/2) q[3];\n",
            "cx q[2],q[3];\n",
            "u1(0.284298969229392) q[3];\n",
            "cx q[2],q[3];\n",
            "u2(0.0,pi) q[2];\n",
            "u3(-pi/2,-pi/2,pi/2) q[3];\n",
            "u3(pi/2,-pi/2,pi/2) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "cx q[2],q[3];\n",
            "u1(-0.284298969229392) q[3];\n",
            "cx q[2],q[3];\n",
            "u3(-pi/2,-pi/2,pi/2) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "u2(0.0,pi) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u3(pi/2,-pi/2,pi/2) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u2(0.0,pi) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u3(-pi/2,-pi/2,pi/2) q[3];\n",
            "u2(0.0,pi) q[0];\n",
            "u3(pi/2,-pi/2,pi/2) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u2(0.0,pi) q[0];\n",
            "u3(-pi/2,-pi/2,pi/2) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "u2(0.0,pi) q[0];\n",
            "u3(pi/2,-pi/2,pi/2) q[1];\n",
            "u3(pi/2,-pi/2,pi/2) q[2];\n",
            "u3(pi/2,-pi/2,pi/2) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u2(0.0,pi) q[0];\n",
            "u3(-pi/2,-pi/2,pi/2) q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[2];\n",
            "u3(-pi/2,-pi/2,pi/2) q[3];\n",
            "u2(0.0,pi) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u3(pi/2,-pi/2,pi/2) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(-0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u2(0.0,pi) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "u3(pi/2,-pi/2,pi/2) q[0];\n",
            "u3(pi/2,-pi/2,pi/2) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u3(pi/2,-pi/2,pi/2) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[0];\n",
            "u3(-pi/2,-pi/2,pi/2) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u3(-pi/2,-pi/2,pi/2) q[3];\n",
            "u3(pi/2,-pi/2,pi/2) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(-0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u2(0.0,pi) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "u3(pi/2,-pi/2,pi/2) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u3(pi/2,-pi/2,pi/2) q[2];\n",
            "u3(pi/2,-pi/2,pi/2) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(-0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[0];\n",
            "u2(0.0,pi) q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[2];\n",
            "u3(-pi/2,-pi/2,pi/2) q[3];\n",
            "u3(pi/2,-pi/2,pi/2) q[0];\n",
            "u3(pi/2,-pi/2,pi/2) q[1];\n",
            "u3(pi/2,-pi/2,pi/2) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "cx q[0],q[1];\n",
            "cx q[1],q[2];\n",
            "cx q[2],q[3];\n",
            "u1(-0.143019766019107) q[3];\n",
            "cx q[2],q[3];\n",
            "cx q[1],q[2];\n",
            "cx q[0],q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[0];\n",
            "u3(-pi/2,-pi/2,pi/2) q[1];\n",
            "u3(-pi/2,-pi/2,pi/2) q[2];\n",
            "u2(0.0,pi) q[3];\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    }
  ]
}